
package com.yimixian.app.goods;

import com.umeng.analytics.MobclickAgent;
import com.yimixian.app.R;
import com.yimixian.app.ui.FragmentGroup;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class GoodDetailFragmentGroup extends FragmentGroup {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragmentgroup_good_detail, container, false);
        return view;
    }

    @Override
    protected void initPrimaryFragment() {
        switchPrimaryFragment(0);
    }

    @Override
    protected void initSecondaryFragment() {
        switchSecondaryFragment(0);
    }

    @Override
    protected Class<? extends Fragment> getPrimaryFragmentClass(
            int fragmentId) {
        return GoodDetailTopFragment.class;
    }

    @Override
    protected Class<? extends Fragment> getSecondaryFragmentClass(
            int fragmentId) {
        return GoodDetailCartFragment.class;
    }

    @Override
    protected Bundle getPrimaryFragmentArguments(int fragmentId) {
        super.getSecondaryFragmentArguments(fragmentId);
        String mGoodId = getArguments().getString(GoodDetailActivity.INTENT_EXTRA_GOOD_ID);
        Bundle bundle = new Bundle();
        bundle.putString(GoodDetailActivity.INTENT_EXTRA_GOOD_ID,mGoodId);
        return bundle;
    }

    @Override
    protected Bundle getSecondaryFragmentArguments(int fragmentId) {
        super.getSecondaryFragmentArguments(fragmentId);
        String mGoodId = getArguments().getString(GoodDetailActivity.INTENT_EXTRA_GOOD_ID);
        Bundle bundle = new Bundle();
        bundle.putString(GoodDetailActivity.INTENT_EXTRA_GOOD_ID,mGoodId);
        return bundle;
    }

    @Override
    protected int getPrimaryFragmentStubId(int fragmentId) {
        return R.id.fl_content_container;
    }

    @Override
    protected int getSecondaryFragmentStubId(int fragmentId) {
        return R.id.fl_cart_container;
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(this.getClass().getSimpleName());
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(this.getClass().getSimpleName());
    }

    public void resetInitDetailCartFragmentPlusMinitIcon() {
        if(mCurrentSecondaryFragment != null && mCurrentSecondaryFragment instanceof GoodDetailCartFragment) {
            ((GoodDetailCartFragment)mCurrentSecondaryFragment).initPlusMinusIcon();
        }
    }
}
